<template>
	<div style="padding-bottom: 180px;">
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
			<uni-forms ref="form" :modelValue="formData" :rules="rules" labelWidth="75px">
				<uni-forms-item v-if="showOldOutCode" label="原运单号">
					<uni-data-select @change="selectOutCode" v-model="formData.oldOutCode" :localdata="oldOutCodeList"
						style="background-color: white;" />
				</uni-forms-item>
				<uni-forms-item label="合作项目">
					<uni-data-select v-model="formData.projectId" :localdata="projectId"
						style="background-color: white;" />
				</uni-forms-item>
				<!-- <uni-forms-item label="运单类型" name="waybillType" required>
					<uni-data-select v-model="formData.waybillType" :localdata="waybillType"
						style="background-color: white;" />
				</uni-forms-item> -->
			</uni-forms>
		</view>
		<!--收发货方-->
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px 15px 25px;display: flex;flex-direction: row;">
			<view style="width: 50px;display: flex;flex-direction: column;">
				<view style="height: 24px;width: 24px;border-radius: 50%;background-color: #464646;color: #ffffff;display: flex;justify-content: center;align-items: center;">发</view>
			    <view style="height: 156px;width: 1px;border-left: 1rpx dashed #bf6006;margin-left: 11px;"></view>
				<view style="height: 24px;width: 24px;border-radius: 50%;background-color: #bf6006;color: #ffffff;display: flex;justify-content: center;align-items: center;">收</view>
			</view>
			<view style="display: flex;flex-direction: column;width: 100%;">
				<view style="display: flex;width: 100%;height: 160px;">
					<!--发货方-->
					<view style="display: flex;flex-direction: column;width: 100%;">
					    <text style="font-size: 16px;font-weight: bold;">发货方信息</text>
					    <span style="display: flex;justify-content: space-between;margin-top: 10px;">
							<uni-data-select @change="selectShipId" v-model="formData.shipId" :localdata="shipId" placeholder="请选择发货方"
								style="background-color: white;width: 100%;" />
					    </span>
					    <span v-if="formData.shipContacts==''||formData.shipContacts==null" style="display: flex;margin-top: 20px;height: 37px;align-items: center;">
					    	<input disabled placeholder="请从地址簿选择发货地址" style="border: none;width: 80%;"/>
					    </span>
						<span v-else style="display: flex;flex-direction: column;margin-top: 10px;">
							<span>
								<text style="font-size: 16px;font-weight: bold;">{{formData.shipContacts}}</text>
								<text style="margin-left: 10px;">{{formData.shipContactTel}}</text>
							</span>
							<span style="font-size: 12px;color: #6f6f6f;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;">
								{{formData.shipDistrictName}}{{formData.shipAddress}}
							</span>
						</span>
						<span style="display: flex;justify-content: space-between;margin-top: 10px;">
							<uni-data-select  v-model="formData.shipNetId" :localdata="shipNetId" placeholder="请选择发货网点"
								style="background-color: white;width: 100%;" />
						</span>
						
				    </view>
					<view style="display: flex;align-items: center;width: 60px;margin-top: 42px">
						<span style="display: flex;align-items: center;font-size: 14px;">
							<view style="width: 1px;height: 14px;background-color: #e7e7e7;margin-right: 5px;"></view>
							<view @click="open_shipAddress" hover-class="buttonHover" style="font-weight: bold;">地址薄</view>
						</span>
					</view>
				</view>
				<!--分割线-->
				<!-- <view style="height: 1px;width: 100%;display: flex;justify-content: center;background-color: #e7e7e7;margin: 10px 0;"></view> -->
				<view style="height: 1px;width: 100%;display: flex;justify-content: center;margin: 10px 0;"></view>
				
				<view style="display: flex;width: 100%;height: 160px;">
					<!--收货方-->
					<view style="display: flex;flex-direction: column;width: 100%;">
					    <text style="font-size: 16px;font-weight: bold;">收货方信息</text>
					    <span style="display: flex;justify-content: space-between;margin-top: 10px;">
					    	<uni-data-select @change="selectDeliveryId" v-model="formData.deliveryId" :localdata="deliveryId" placeholder="请选择收货方"
					    		style="background-color: white;width: 100%;" />
					    </span>
					    <span v-if="formData.deliveryContacts==''||formData.deliveryContacts==null" style="display: flex;margin-top: 20px;height: 37px;align-items: center;">
							<input disabled placeholder="请从地址簿选择收货地址" style="border: none;width: 80%;"/>
					    </span>
						<span v-else style="display: flex;flex-direction: column;margin-top: 10px;">
							<span>
								<text style="font-size: 16px;font-weight: bold;">{{formData.deliveryContacts}}</text>
								<text style="margin-left: 10px;">{{formData.deliveryContactTel}}</text>
							</span>
							<span style="font-size: 12px;color: #6f6f6f;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;">
								{{formData.deliveryDistrictName}}{{formData.deliveryAddress}}
							</span>
						</span>
						<span style="display: flex;justify-content: space-between;margin-top: 10px;">
							<uni-data-select v-model="formData.deliveryNetId" :localdata="deliveryNetId" placeholder="请选择收货网点"
								style="background-color: white;width: 100%;" />
						</span>
				    </view>
					<view style="display: flex;align-items: center;width: 60px;margin-top: 42px">
						<span style="display: flex;align-items: center;font-size: 14px;">
							<view style="width: 1px;height: 14px;background-color: #e7e7e7;margin-right: 5px;"></view>
							<view @click="open_deliveryAddress" hover-class="buttonHover" style="font-weight: bold;">地址薄</view>
						</span>
					</view>
				</view>
			</view>
			
		</view>
		<!--物品信息-->
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
			<uni-forms :modelValue="formData" labelWidth="70px">
				<uni-forms-item label="物品信息" required>
					<view style="display: flex;justify-content: space-between;width: 100%;padding-top: 8px;">
						<view v-if="spread" style="flex: 1;">
							<text v-if="formData.goodSourceList.length>0">{{formData.goodSourceList[0].goodsName}}，{{formData.goodSourceList[0].weight}}吨，{{formData.goodSourceList[0].bulk}}立方米，{{formData.goodSourceList[0].num}}件</text>
							<text v-else>请添加物品</text>
						</view>
						<view v-else style="display: flex;flex-direction: column;flex: 1;">
							<span v-for="(item,index) in formData.goodSourceList" :key="index" style="display: flex;align-items: center;margin-bottom: 10px;">
								<view style="flex: 2;">{{item.goodsName}}，{{item.weight}}吨，{{item.bulk}}立方米，{{item.num}}件</view>
								<view style="flex: 1;display: flex;">
									<view @click="editGoodsList(index)" hover-class="buttonHover"><uni-icons type="compose" size="18" color="#bf5f09"></uni-icons></uni-icons></view>
									<view @click="deleteGoodsList(index)" hover-class="buttonHover" style="margin-left: 10px;"><uni-icons type="trash" size="18" color="#bf5f09"></uni-icons></view>
								</view>
							</span>
						</view>
						<view style="display: flex;justify-content: flex-end;width: 112px;">
							<view  @click="spreadAndShrink" style="color: #464646;">
								<span v-if="spread" style="display: flex;align-items: center;">
									<view style="background-color: #bf6006;color: #ffffff;border-radius: 50%;display: flex;justify-content: center;align-items: center;width: 18px;height: 18px;">
										{{formData.goodSourceList.length}}
									</view>
									展开<uni-icons type="bottom" size="14" color="#464646"></uni-icons>
								</span>
								<span v-else>
									隐藏<uni-icons type="top" size="14" color="#464646"></uni-icons>
								</span>
							</view>
							<view @click="addGoods" hover-class="buttonHover" style="color: #bf6006;margin-left: 10px;">添加<uni-icons type="plusempty" size="14" color="#bf6006"></uni-icons></view>
						</view>
					</view>
				</uni-forms-item>
				<!-- <uni-forms-item label="上传" name="file">
					<myfilepicker @clickFile="clickFile" limit="3" :value="fileList" file-extname="pdf,png,gif,jpg,jpeg,doc,docx" file-mediatype="all" @select="selectFile"  @delete='deleteFile' @success="success" @fail="fail"
							title="*点击可上传物品附件，支持png/jpg/jpeg/doc/docx/xls/xlsx/pdf，最多可上传3个附件*"></myfilepicker>
					</uni-forms-item>
				</uni-forms-item> -->
				<view style="display: flex;">
					<view style="flex: 1;margin-right: 5px;">
						<uni-forms-item label="总包装费"  name="totalPackingFee">
							<uni-easyinput type="text" v-model="formData.totalPackingFee" placeholder="总包装费" />
						</uni-forms-item>
					</view>
					<view style="flex: 1;">
						<uni-forms-item label="里程运费" labelAlign="right" name="totalMileageFee">
							<uni-easyinput  type="text" v-model="formData.totalMileageFee" placeholder="里程运费" />
						</uni-forms-item>
					</view>
				</view>
				<uni-forms-item label="总运费"  name="totalCarriageFee">
					<uni-easyinput type="text" v-model="formData.totalCarriageFee" placeholder="总运费" />
				</uni-forms-item>
			</uni-forms>
		</view>
		<!--运送时效要求-->
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
			<uni-forms ref="form" :modelValue="formData" labelWidth="96px">
				<!-- <uni-forms-item label="运送时效要求" name="deliveryTimeReq">
					<view style="display: flex;justify-content: space-between;">
						<uni-data-checkbox mode="tag" v-model="formData.deliveryTimeReq" selectedColor="#bf5f09" selectedTextColor="white" :localdata="deliveryTimeReq"></uni-data-checkbox>
						<checkbox-group style="padding-top: 8px;" @change="checkboxChange">
							<label>
								<checkbox value="1" :checked="formData.cargoControl=='1'" />控货
							</label>
						</checkbox-group>
					</view>
				</uni-forms-item> -->
				<uni-forms-item label="是否控货" name="cargoControl">
					<checkbox-group style="padding-top: 8px;" @change="checkboxChange">
						<label>
							<checkbox value="1" :checked="formData.cargoControl=='1'" />控货
						</label>
					</checkbox-group>
				</uni-forms-item>
				<uni-forms-item label="计划提货时间">
					<uni-datetime-picker type="datetime" v-model="formData.shipPlanTime" />
				</uni-forms-item>
				<uni-forms-item label="发货提货方式"  name="shipPickUpWay">
					<uni-data-select v-model="formData.shipPickUpWay" :localdata="shipPickUpWay"
						style="background-color: white;" />
					<view style="margin-top: 20px;">
						<uni-easyinput type="number" v-model="formData.shipPickUpFee" placeholder="提货费" />
					</view>
				</uni-forms-item>
				<!-- <uni-forms-item label="预约时间">
					<uni-datetime-picker type="datetime" v-model="formData.shipAppointmentTime" />
				</uni-forms-item> -->
				<uni-forms-item label="计划到达时间">
					<uni-datetime-picker type="datetime" v-model="formData.deliveryPlanTime" />
				</uni-forms-item>
				<uni-forms-item label="到达提货方式"  name="deliveryPickUpWay">
					<uni-data-select v-model="formData.deliveryPickUpWay" :localdata="deliveryPickUpWay"
						style="background-color: white;" />
					<view style="margin-top: 20px;">
						<uni-easyinput type="number" v-model="formData.deliveryPickUpFee" placeholder="送货费" />
					</view>
				</uni-forms-item>
				<!-- <uni-forms-item label="预约时间">
					<uni-datetime-picker type="datetime" v-model="formData.deliveryAppointmentTime" />
				</uni-forms-item> -->
			</uni-forms>
		</view>
		<!--货值声明-->
		<!-- <view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;height: 35px;">
			<uni-forms labelWidth="75px">
				<view style="display: flex;">
					<view style="flex: 1;">
						<uni-forms-item label="货值声明">
							<uni-easyinput type="text" v-model="formData.goodsValue" placeholder="货值声明" />
						</uni-forms-item>
					</view>
					<view style="flex: 1;">
						<uni-forms-item label="保价费" labelAlign="right" labelWidth="60px">
							<view style="display: flex;align-items: center;">
								<uni-easyinput type="number" v-model="formData.protectMoney" placeholder="保价费" />
								<uni-icons type="help" size="20" color="#999" style="margin-left: 5px;"></uni-icons>
							</view>
						</uni-forms-item>
					</view>
				</view>
			</uni-forms>
			
		</view> -->
		<!--增值服务-->
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;height: 35px;">
			<uni-forms labelWidth="75px">
				<uni-forms-item label="增值服务" >
					<uni-list-item @click="bindPickerChangeIncrementService" :border="false" :title="JSON.stringify(formData.waybillValueAdd)=='{}'?'请选择增值服务':'编辑增值服务'" showArrow clickable  style="height: 36px;"/>
				</uni-forms-item>
			</uni-forms>
		</view>
		<!--消费抵扣-->
		<!-- <view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;height: 35px;">
			<uni-forms labelWidth="75px">
				<uni-forms-item label="消费抵扣" >
					<picker @change="bindPickerChangeConsumeDeduction" :value="index_consumeDeduction" :range="array_consumeDeduction">
						<uni-list-item  :border="false" :title="formData.consumeDeduction" showArrow  style="height: 36px;"/>
					</picker>
					
				</uni-forms-item>
			</uni-forms>
		</view> -->
		<!--结算方式-->
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
			<uni-forms  :modelValue="waybillFee" labelWidth="75px">
				<uni-forms-item label="结算方式" name="settlementMode" required>
					<uni-data-select v-model="waybillFee.settlementMode" :localdata="settlementMode"
						style="background-color: white;" />
					<view style="margin-top: 20px;">
						<!--现付-->
						<!-- <span style="display: flex;align-items: center;"
							v-if="waybillFee.settlementMode=='1'">
							<view style="flex: 2;">
								<uni-easyinput type="text" v-model="waybillFee.cod"
									placeholder="现付金额" />
							</view>
							<view style="flex: 1;margin-left: 5px;">/元</view>
						</span> -->
						<!--到付-->
						<!-- <span style="display: flex;align-items: center;"
							v-if="waybillFee.settlementMode=='2'">
							<view style="flex: 2;">
								<uni-easyinput type="text" v-model="waybillFee.pod"
									placeholder="到付金额" />
							</view>
							<view style="flex: 1;margin-left: 5px;">/元</view>
						</span> -->
						<!--欠付-->
						<!-- <span style="display: flex;align-items: center;"
							v-if="waybillFee.settlementMode=='3'">
							<view style="flex: 2;">
								<uni-easyinput type="text" v-model="waybillFee.poa"
									placeholder="欠付金额" />
							</view>
							<view style="flex: 1;margin-left: 5px;">/元</view>
						</span> -->
						<!--回单付-->
						<!-- <span style="display: flex;align-items: center;"
							v-if="waybillFee.settlementMode=='4'">
							<view style="flex: 2;">
								<uni-easyinput type="text" v-model="waybillFee.pom"
									placeholder="回单付金额" />
							</view>
							<view style="flex: 1;margin-left: 5px;">/元</view>
						</span> -->
						<!--月付-->
						<span style="display: flex;align-items: center;"
							v-if="waybillFee.settlementMode=='5'">
							<!-- <view style="flex: 1;">
								<uni-easyinput type="text" v-model="waybillFee.ms"
									placeholder="月付金额" />
							</view> -->
							<view style="flex: 1;">
								<uni-combox :candidates="payType_day" placeholder="请选择天数"
									v-model="waybillFee.msDay"></uni-combox>
							</view>
						</span>
						<!--混合付-->
						<!-- <span style="display: flex;flex-direction: column;"
							v-else-if="waybillFee.settlementMode=='7'">
							<span style="display: flex;align-items: center;">
								<view style="flex: 2;">
									<uni-easyinput type="text" v-model="waybillFee.cod"
										placeholder="现付" />
								</view>
								<view style="flex: 1;margin-left: 5px;">/元</view>
				
								<view style="flex: 2;">
									<uni-easyinput type="text" v-model="waybillFee.pod"
										placeholder="到付" />
								</view>
								<view style="flex: 1;margin-left: 5px;">/元</view>
							</span>
							<span style="display: flex;align-items: center;margin-top: 20px;">
								<view style="flex: 2;">
									<uni-easyinput type="text" v-model="waybillFee.poa"
										placeholder="欠付" />
								</view>
								<view style="flex: 1;margin-left: 5px;">/元</view>
				
								<view style="flex: 2;">
									<uni-easyinput type="text" v-model="waybillFee.pom"
										placeholder="回单付" />
								</view>
								<view style="flex: 1;margin-left: 5px;">/元</view>
							</span>
							<span style="display: flex;align-items: center;margin-top: 20px;">
								<view style="flex: 1;">
									<uni-easyinput type="text" v-model="waybillFee.ms"
										placeholder="月结金额" />
								</view>
								<view style="flex: 1;margin-left: 5px;">
									<uni-combox :candidates="payType_day" placeholder="请选择天数"
										v-model="formData.monthlyDays"></uni-combox>
								</view>
							</span>
						</span> -->
					</view>
				</uni-forms-item>
			</uni-forms>
		</view>
		<!--经办人&联系电话-->
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
			<uni-forms ref="form" :modelValue="formData.waybillCarrier" labelWidth="75px">
				<uni-forms-item label="经办人">
					<uni-easyinput type="text" v-model="formData.waybillCarrier.agent" placeholder="经办人" />
				</uni-forms-item>
				<uni-forms-item label="联系电话">
					<uni-easyinput type="text" v-model="formData.waybillCarrier.tel" placeholder="联系电话" />
				</uni-forms-item>
			</uni-forms>
		</view>
		<!--运价说明-->
		<view v-if="!moreSetting" style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;height: 35px;">
			<uni-forms ref="form" :modelValue="formData" labelWidth="75px">
				<uni-forms-item label="运价说明">
					<view style="display: flex;justify-content: space-between;">
						<uni-icons @click="tips" type="help" size="20" color="#999" style="padding-top: 8px;"></uni-icons>
						<view @click="clickMoreSetting(true)" hover-class="buttonHover" style="padding-top: 8px;color: #bf6006;">
							更多设置
						</view>
					</view>
				</uni-forms-item>
			</uni-forms>
		</view>
		<!--更多设置-->
		<view v-else style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
			<uni-forms ref="form" :modelValue="formData.waybillCarrier" labelWidth="75px">
				<view style="display: flex;">
					<view style="margin-right: 30px;">
						<checkbox-group style="padding-top: 8px;" @change="carrierObjectFlag=!carrierObjectFlag">
							<label>
								<checkbox :value="false" :checked="carrierObjectFlag" />设置承运商
							</label>
						</checkbox-group>
					</view>
					<view style="flex: 1;margin-right: 5px;">
						<uni-forms-item label="承运方" style="width: 90%;" labelWidth="55px">
							<uni-data-select :disabled="!carrierObjectFlag" v-model="formData.waybillCarrier.carrierObjectId" :localdata="carrierObjectId"
								style="background-color: white;" />
						</uni-forms-item>
					</view>
				</view>
				<uni-forms-item label="司机姓名" required>
					<uni-combox @input="inpuTdriverName" v-model="formData.waybillCarrier.driverName" :candidates="driverName" placeholder="输入检索司机"></uni-combox>
					<!-- <uni-easyinput type="text" v-model="formData.waybillCarrier.driverName" placeholder="司机姓名" /> -->
				</uni-forms-item>
				<uni-forms-item label="身份证号" required>
					<uni-combox @input="inpuIdriverCardId" v-model="formData.waybillCarrier.driverCardId" :candidates="driverCardId" placeholder="输入检索司机身份证号"></uni-combox>
					<!-- <uni-easyinput type="text" v-model="formData.waybillCarrier.driverCardId" placeholder="身份证号" /> -->
				</uni-forms-item>
				<uni-forms-item label="司机电话" required>
					<uni-combox @input="inpuTdriverCardTel" v-model="formData.waybillCarrier.driverCardTel" :candidates="driverCardTel" placeholder="输入检索司机联系电话"></uni-combox>
					<!-- <uni-easyinput type="number" v-model="formData.waybillCarrier.driverCardTel" placeholder="司机电话" /> -->
				</uni-forms-item>
				<uni-forms-item label="车牌号" required>
					<uni-combox @input="inputPlateNumber" :candidates="plateNumber" placeholder="输入检索车牌号"
						v-model="formData.waybillCarrier.driverCarId"></uni-combox>
					<view v-if="carInfo.carId">
						{{carType_[carInfo.carType]}} {{carInfo.carLength}}米，行驶证号：{{carInfo.drivingLicenseNo}}
					</view>
					<!-- <uni-easyinput type="text" v-model="formData.waybillCarrier.driverCarId" placeholder="车牌号" /> -->
				</uni-forms-item>
				<uni-forms-item label="车型" required>
					<uni-data-select  v-model="formData.waybillCarrier.vehicle" :localdata="vehicle"
						style="background-color: white;" />
				</uni-forms-item>
				<view v-if="scheduleList.length!=0" style="margin-top: 10px;margin-bottom: 10px;display: flex;align-items: center;">
					当前有调度车次信息，选择当前运单加入
					<button @click="openSelectScheduleList" hover-class="buttonHover" style="background-color: #2979ff;color: white;" size="mini">选择</button>
				</view>
				<view v-if="scheduleList.length!=0&&scheduleVo.scheduleNo" style="margin-bottom: 10px;font-weight: bold;">车次号：{{schedule.scheduleNo}}</view>
				<!-- <uni-forms-item label="挂车牌号">
					<uni-easyinput type="text" v-model="formData.waybillCarrier.driverTrailerId" placeholder="挂车牌号" />
				</uni-forms-item> -->
				<!-- <uni-forms-item label="经办人">
					<uni-easyinput type="text" v-model="formData.waybillCarrier.agent" placeholder="挂车牌号" />
				</uni-forms-item>
				<uni-forms-item label="联系电话">
					<uni-easyinput type="text" v-model="formData.waybillCarrier.tel" placeholder="联系电话" />
				</uni-forms-item> -->
				<uni-forms-item label="备注" name="remark">
					<uni-easyinput type="textarea" v-model="formData.remark" placeholder="运单相关备注说明" />
				</uni-forms-item>
				<uni-forms-item label="运价说明">
					<view style="display: flex;justify-content: space-between;">
						<uni-icons @click="tips" type="help" size="20" color="#999" style="padding-top: 8px;"></uni-icons>
						<view @click="clickMoreSetting(false)" hover-class="buttonHover" style="padding-top: 8px;color: #bf6006;">
							收起
						</view>
					</view>
				</uni-forms-item>
			</uni-forms>
			<!-- <view @click="moreSetting=!moreSetting" hover-class="buttonHover" style="color: #bf6006;text-align: end;">
				收起
			</view> -->
		</view>
		<!--费用计算-->
		<view v-if="totalPrice!='0.00'" style="background-color: #929292;z-index: 3;width:100%;position: fixed;bottom: 80px;font-size: 14px;">
			<view style="margin: 5px 20px;">
				<text>费用计算：</text>
				<text style="color: #ffffff;">
					<text v-if="Number(formData.totalCarriageFee)">总运费{{Number(formData.totalCarriageFee).toFixed(2)}}</text>
					<text v-if="Number(formData.totalPackingFee)">+总包装费{{Number(formData.totalPackingFee).toFixed(2)}}</text>
					<text v-if="Number(formData.shipPickUpFee)">+提货费{{Number(formData.shipPickUpFee).toFixed(2)}}</text>
					<text v-if="Number(formData.deliveryPickUpFee)">+送货费{{Number(formData.deliveryPickUpFee).toFixed(2)}}</text>
					<text v-if="Number(formData.waybillValueAdd.parcelInsuranceFee)">+保价费{{Number(formData.waybillValueAdd.parcelInsuranceFee).toFixed(2)}}</text>
					<text v-if="Number(formData.waybillValueAdd.receiptFee)">+回单费{{Number(formData.waybillValueAdd.receiptFee).toFixed(2)}}</text>
					<text v-if="Number(formData.waybillValueAdd.warehouseFee)">+仓储费{{Number(formData.waybillValueAdd.warehouseFee).toFixed(2)}}</text>
					<text v-if="Number(formData.waybillValueAdd.loadingFee)">+装货费{{Number(formData.waybillValueAdd.loadingFee).toFixed(2)}}</text>
					<text v-if="Number(formData.waybillValueAdd.unloadFee)">+卸货费{{Number(formData.waybillValueAdd.unloadFee).toFixed(2)}}</text>
					<text v-if="Number(formData.waybillValueAdd.drayage)">+短驳费{{Number(formData.waybillValueAdd.drayage).toFixed(2)}}</text>
					<!-- <text v-if="Number(formData.waybillValueAdd.carryFee)">+搬运费{{Number(formData.waybillValueAdd.carryFee).toFixed(2)}}</text> -->
					<text v-if="Number(formData.waybillValueAdd.otherFee)">+其他费用{{Number(formData.waybillValueAdd.otherFee).toFixed(2)}}</text>
				</text>
				<text style="margin-left: 10px;">预估总价￥{{totalPrice}}</text>
			</view>
		</view>
		<!--下单-->
		<view style="background-color: #ffffff;z-index: 3;height: 80px;width:100%;position: fixed;bottom: 0;display: flex;justify-content: center;box-shadow: 0px 0px 11px rgba(0, 0, 0, 0.1);">
			<view style="display: flex;justify-content: space-between;align-items: center;width: 90%;height: 60px">
				<view style="font-size: 15px;">
					应付总价：
					<text style="color: #fc7a7a;font-weight: bold;font-size: 18px;">￥{{totalPrice}}</text>
				</view>
				<view style="display: flex;">
					<view v-if="waybillId==''" @click="autoConfirm" hover-class="buttonHover" style="width: 70px;height: 30px;color: #bf5f09;background-color: #ffffff;border:1px solid #bf5f09;font-size: 18px;display: flex;justify-content: center;align-items: center;border-radius: 4px;margin-right: 10px;">保存</view>
					<view v-else @click="updateWayBillProfile" hover-class="buttonHover" style="width: 70px;height: 30px;color: #bf5f09;background-color: #ffffff;border:1px solid #bf5f09;font-size: 18px;display: flex;justify-content: center;align-items: center;border-radius: 4px;margin-right: 10px;">保存</view>
					<view @click="dialogToggle" hover-class="buttonHover" style="width: 70px;height: 30px;background-color: #bf5f09;color: #ffffff;font-size: 18px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">下单</view>
				</view>
				
				<!-- <view style="width: 70px;height: 30px;background-color: #d9d9d9;color: #ffffff;font-size: 18px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">下单</view> -->
			</view>
		</view>
		<!-- 运价说明弹窗 -->
		<uni-popup ref="popup" background-color="#fff">
			<view style="display: flex;width: 280px;flex-direction: column;padding: 10px;">
				<text>运输价格：常规价格方案</text>
				<text>应用范围：通用价格</text>
				<text>计费方式：综合质量体积</text>
				<text>更新时间：2023-01-11 18：25：00</text>
				<text>计费标准：</text>
				<text>里程：首里程0KM~5KM 2000元 ， 续里程3KM~5KM 200元、5KM~10KM 200元。</text>
				<text>重量：首重0kg~5kg 2000元 ， 续重3kg~5kg 200元、续重8kg~15kg 180元。</text>
				<text>体积重量：轻泡系数 6000，首重0kg~5kg 2000元 ， 续重3kg~5kg 210元。</text>
			</view>
		</uni-popup>
		<!-- 下单提示窗 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="提交" title="确认提交退货运单" @confirm="dialogConfirm">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 200px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<!-- <view style="display: flex;">
							<text style="width: 75px;">运单编号：</text>
							<text style="font-weight: bold;margin-left: 20px;">Y185655850</text>
						</view> -->
						<!-- <view style="display: flex;">
							<text style="width: 75px;">发货网点：</text>
							<text style="margin-left: 20px;">{{formData.deliveryDot}}</text>
						</view> -->
						<view style="display: flex;">
							<text style="width: 75px;">发货方：</text>
							<text style="margin-left: 20px;">{{formData.shipName}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">收货方：</text>
							<text style="margin-left: 20px;">{{formData.deliveryName}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">始发地：</text>
							<text style="margin-left: 20px;">{{formData.shipDistrictName}}{{formData.shipAddress}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">目的地：</text>
							<text style="margin-left: 20px;">{{formData.deliveryDistrictName}}{{formData.deliveryAddress}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">收货方联系人：</text>
							<text style="margin-left: 20px;">{{formData.deliveryContacts}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">联系电话：</text>
							<text style="margin-left: 20px;">{{formData.deliveryContactTel}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">承运商：</text>
							<text style="margin-left: 20px;">经办人{{formData.waybillCarrier.agent}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">司机姓名：</text>
							<text style="margin-left: 20px;">{{formData.waybillCarrier.driverName}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">司机电话：</text>
							<text style="margin-left: 20px;">{{formData.waybillCarrier.driverCardTel}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">身份证号：</text>
							<text style="margin-left: 20px;">{{formData.waybillCarrier.driverCardId}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">车牌号：</text>
							<text style="margin-left: 20px;">{{formData.waybillCarrier.driverCarId}}</text>
						</view>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
		<!-- 发货地址簿弹窗 -->
		<uni-popup ref="alertDialog_address_ship" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确定" title="地址薄" @confirm="dialogConfirm_address_ship">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 200px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<radio-group @change="radioChange_ship">
							<label v-for="(item, index) in addressList_ship" :key="index"
								style="display: flex;flex-direction: column;background-color: white;padding: 15px;border-bottom: 1rpx solid #ededed;">
								<view style="display: flex;">
									<text>{{item.contactName}}</text>
									<text style="margin-left: 20px;">{{item.phone}}</text>
								</view>
								<view style="position: relative;margin-top: 10px;">
									<radio :value="JSON.stringify(item)" :checked="item.id===address_ship.id"/>
									<text style="margin-left: 10px;">{{item.bookDistrictName}}{{item.bookAddress}}</text>
								</view>
							</label>
						</radio-group>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
		<!-- 收货地址簿弹窗 -->
		<uni-popup ref="alertDialog_address_delivery" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确定" title="地址薄" @confirm="dialogConfirm_address_delivery">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 200px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<radio-group @change="radioChange_delivery">
							<label v-for="(item, index) in addressList_delivery" :key="index"
								style="display: flex;flex-direction: column;background-color: white;padding: 15px;border-bottom: 1rpx solid #ededed;">
								<view style="display: flex;">
									<text>{{item.contactName}}</text>
									<text style="margin-left: 20px;">{{item.phone}}</text>
								</view>
								<view style="position: relative;margin-top: 10px;">
									<radio :value="JSON.stringify(item)" :checked="item.id===address_delivery.id"/>
									<text style="margin-left: 10px;">{{item.bookDistrictName}}{{item.bookAddress}}</text>
								</view>
							</label>
						</radio-group>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
		<!-- 调度车次列表弹窗 -->
		<uni-popup ref="alertDialog_scheduleList" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确定" title="当前调度车次" @confirm="dialogConfirm_scheduleList">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 200px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<radio-group @change="radioChange_scheduleList">
							<label v-for="(item, index) in scheduleList" :key="index"
								style="display: flex;flex-direction: column;background-color: white;padding: 15px;border-bottom: 1rpx solid #ededed;">
								<view style="display: flex;">
									<text>{{item.scheduleNo}}</text>
									<text style="margin-left: 20px;">{{scheduleStatus[item.flowStatus]}}</text>
								</view>
								<view style="position: relative;margin-top: 10px;">
									<radio :value="JSON.stringify(item)" :checked="item.scheduleId===schedule.scheduleId" :disabled="[0,410,420,430,440].includes(item.flowStatus)"/>
									<text style="margin-left: 10px;">{{item.lineVo.lineName}}</text>
								</view>
							</label>
						</radio-group>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
	</div>
</template>

<script>
	import {getWayBillDetails,getWayBillList} from '@/api/system/waybill.js';
	import {addWayBill,updateWayBillProfile,updateWayBillStatus} from '@/api/system/return.js';
	import {getProjectList,getDeptList} from '@/api/system/project.js';
	import {getCustomerList,} from '@/api/system/customer.js';
	import {getCarrierList,} from '@/api/system/carrier.js';
	import {getPlanPriceList} from '@/api/system/planPrice.js'
	import {getDriverList,getCarrierCarList,getCarrierCarDetails} from '@/api/system/driver.js';
	import {getScheduleListByDriverId,updateSchedule} from '@/api/system/dispatch.js'
	import {getDicts} from '@/api/system/dict.js'
	
	
	export default {
		data() {
			return {
				showOldOutCode:true,//是否显示原运单
				formData: {
					oldOutCode:'',
					projectId:'',
					waybillType:'',
					shipId:'',        //发货方ID
					shipName:'',     //发货方名
					shipContacts:'', //发货方联系人
					shipContactTel:'', //发货方联系电话
					shipDistrictId:'',//发货方省市区、县ID
					shipDistrictName:'',//发货方省市区名称
					shipAddress:'',  //发货方详细地址
					shipNetId:"",   //发货方网点ID
					
					deliveryId:'',        //收货方ID
					deliveryName:'',     //收货方名
					deliveryContacts:'', //收货方联系人
					deliveryContactTel:'', //收货方联系电话
					deliveryDistrictId:'',//收货方省市区、县ID
					deliveryDistrictName:'',//收货方省市区名称
					deliveryAddress:'',  //收货方详细地址
					deliveryNetId:"",   //收货方网点ID
					
					goodSourceList:[],  //物品列表
					totalPackingFee:'',  //总包装费
					totalMileageFee:'',  //里程运费
					totalCarriageFee:'', //总运费
					
					deliveryTimeReq:'0',  //时效要求
					cargoControl:'',  //控货
					shipPlanTime:'',
					shipPickUpWay:'',
					shipPickUpFee:'',
					shipAppointmentTime:'', //发货方预约发货时间
					arriveTime:'',
					deliveryPickUpWay:'',
					deliveryPickUpFee:'',
					deliveryAppointmentTime:'', //收货方预约发货时间
					
					// goodsValue:'',   //货值声明
					// protectMoney:'', //保价费
					
					waybillValueAdd:{},  //增值服务
					//consumeDeduction:'', //消费抵扣(暂时不做)
					waybillFee:{},
					waybillCarrier:{
						carrierObjectId:'',
						driverName:'',
						driverCardId:'',
						driverCardTel:'',
						vehicle:'',
						driverCarId:'',
						driverTrailerId:'',
						agent:'',
						tel:'',
					},
					remark:'',
				},
				// 校验规则
				rules: {
					oldOutCode:{
						rules: [{
							required: true,
							errorMessage: '请选择原运单号',
						}]
					},
					// waybillType: {
					// 	rules: [{
					// 		required: true,
					// 		errorMessage: '请选择运单类型',
					// 	}]
					// },
					totalPackingFee: {
						rules: [{
							required: true,
							errorMessage: '请输入总包装费',
						}]
					},
					totalMileageFee: {
						rules: [{
							required: true,
							errorMessage: '请输入里程运费',
						}]
					},
					totalCarriageFee: {
						rules: [{
							required: true,
							errorMessage: '请输入总运费',
						}]
					},
					deliveryTimeReq: {
						rules: [{
							required: true,
							errorMessage: '请选择运输时效',
						}]
					},
					totalCarriageFee: {
						rules: [{
							required: true,
							errorMessage: '请输入总运费',
						}]
					},
					idCardNo: {
						rules: [{
							required: true,
							errorMessage: '请输入身份证号',
						},
						{
						    pattern: '(^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}$)',
						    errorMessage: "请输入正确的身份证号"
						}
						]
					},
				},
				//承运商单选框选中状态
				carrierObjectFlag:false,
				//下拉框 ->原运单号
				oldOutCodeList:[],
				//下拉框 ->合作项目
				projectId: [],
				//下拉框 ->运单类型
				waybillType: [],
				
				//下拉框->选择发货方
				shipId: [],
				shipCustomer:[],
				//下拉框->选择发货网点
				shipNetId: [],
				
				//下拉框->选择收货方
				deliveryId: [],
				deliveryCustomer:[],
				//下拉框->选择收货网点
				deliveryNetId: [],
				
				//回显的地址列表
				addressList_ship:[],
				addressList_delivery:[],
				
				//地址弹窗选择的地址
				address_ship:{},
				address_delivery:{},
				
				waybillFee:{
					settlementMode:'',
					cod:'',  //现付
					pod:'',  //到付
					poa:'',  //欠付
					pom:'',  //回单付
					ms:''   //月付
				},
				//下拉框 ->月结多少天
				payType_day: ['7', '15', '30', '45', '60'],
				//物品信息是否收缩
				spread:true,
				
				//运送时效要求
				deliveryTimeReq: [{
						text: '常规',
						value: '1'
					},
					{
						text: '特快',
						value: '2'
					}
				],
				//下拉框->发货提货方式
				shipPickUpWay: [],
				//下拉框->到达提货方式
				deliveryPickUpWay: [],
				
				//选择框->选择消费抵扣
				array_consumeDeduction: ['','中国', '美国', '巴西', '日本'],
				index_consumeDeduction:0,
				
				//结算模式->下拉框
				settlementMode:[],
				
				//更多设置
				moreSetting:false,
				//承运方->下拉框
				carrierObjectId:[],
				//下拉框->司机
				driverName:[],
				//下拉框->司机身份证号
				driverCardId:[],
				//下拉框->司机电话
				driverCardTel:[],
				//所有司机集合
				allDriverList:[],
				driverJson:{},
				
				//下拉框 ->车牌号
				plateNumber: [],
				plateNumberName:'',
				//节流函数标志
				statu:true,
				carInfo:[],
				carJson:{},
				carType_:[],
				//车型->下拉框
				vehicle:[],
				
				//车次列表
				scheduleList:[],
				//车次弹窗选择的车次
				schedule:{},
				//车次弹窗确认选择的车次
				scheduleVo:{},
				
				//车辆调度状态
				scheduleStatus:[],
				
				//运单id
				waybillId:'',
				//原运单id
				oldOutCode:''
			}
		},
		onLoad(e) {
			// var waybillDraft=uni.getStorageSync('waybillDraft')
			// if (waybillDraft) {
			// 	//设置顶部导航栏标题
			// 	uni.setNavigationBarTitle({
			// 		title: '新增运单-草稿'
			// 	})
				
			// 	this.formData=waybillDraft
			// 	this.waybillFee=this.formData.waybillFee
			// }
			if (e.returnWaybillId) {
				//设置顶部导航栏标题
				uni.setNavigationBarTitle({
					title: '新增退货运单-草稿'
				})
				
				uni.showLoading({
					title: '正在加载',
				})
				this.waybillId=e.returnWaybillId
				//获取退货运单详情
				getWayBillDetails(e.returnWaybillId).then(res => {
					uni.hideLoading()
					if (res.code == '200') {
						this.formData = res.data
						//承运商收、放状态
						this.moreSetting=this.formData.waybillCarrier.driverName?true:false;
						//承运商单选框选中状态
						this.carrierObjectFlag=this.formData.waybillCarrier.carrierObjectId?true:false;
						this.waybillFee=this.formData.waybillFee
						this.oldOutCode=this.formData.oldOutCode
						this.calculate()  //计算总运费、总包装费
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			}
			//从运单退货跳转过来的
			if (e.waybillId) {
				this.showOldOutCode=false;  //隐藏原运单选择框
				
				//设置顶部导航栏标题
				uni.setNavigationBarTitle({
					title: '新增退货运单'
				})
				
				uni.showLoading({
					title: '正在加载',
				})
				this.waybillId=e.waybillId
				//获取退货运单详情
				getWayBillDetails(e.waybillId).then(res => {
					uni.hideLoading()
					if (res.code == '200') {
						console.log(res.data)
						this.formData = res.data
						//承运商收、放状态
						this.moreSetting=this.formData.waybillCarrier.driverName?true:false;
						//承运商单选框选中状态
						this.carrierObjectFlag=this.formData.waybillCarrier.carrierObjectId?true:false;
						this.waybillFee=this.formData.waybillFee
						this.oldOutCode=this.formData.outCode
						
						//作退货单处理
						this.formData.waybillId='';
						this.formData.oldOutCode=this.formData.outCode
						this.formData.outCode=''
						
						//清空其余数据
						delete this.formData.pickupVo //提货数据
						delete this.formData.scheduleNo
						delete this.formData.scheduleStatus
						delete this.formData.scheduleVo
						delete this.formData.signVo
						delete this.formData.status;
						
						this.calculate()  //计算总运费、总包装费
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			}
		},
		created() {
			//获取原运单号 可退货运单必须是发车之后，在途标记（到站拦截、异常）并且是到站卸货、签收(含部分签收)、完成状态运单。
			getWayBillList({pageNum:1,pageSize:1000,statusList:[140,160,170,180,190,200,210,220,230]}).then(res => {
				this.oldOutCodeList=res.rows.map(item=>{
					return {
						value:item.outCode,
						text:item.outCode,
						waybillDetails:JSON.stringify(item)
					}
				})
			})
			
			//获取合作项目下拉框
			getProjectList({pageNum:1,pageSize:1000}).then(res=>{
				this.projectId=res.rows.map(item=>{
					return {
						value:item.id,
						text:item.projectName+' '+item.leader+' '+item.phone
					}
				})
			})
			//获取客户列表
			getCustomerList({pageNum:1,pageSize:1000}).then(res => {
				//发货方下拉数据
				this.shipId = res.rows.map(item => {
					return {
						value: item.customerId,
						customer:JSON.stringify(item),
						text: item.customerName
					}
				})
				//收货方下拉数据
				this.deliveryId = JSON.parse(JSON.stringify(this.shipId))
			})
			//加载运单类型
			getDicts('waybill_type').then(res=>{
				this.waybillType=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
			//获取部门网点
			getDeptList().then(res=>{
				//发货方
				this.shipNetId=res.data.map(item=>{
					return {
						value:item.deptId,
						text:'【'+(item.deptType==='3'?'部门':'网点')+'】'+item.deptName
					}
				})
				//收货方
				this.deliveryNetId = JSON.parse(JSON.stringify(this.shipNetId))
			})
			//获取发货提货方式下拉框
			getDicts('send_pickup_method').then(res=>{
				this.shipPickUpWay=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
			//获取到达货提货方式下拉框
			getDicts('recv_pickup_method').then(res=>{
				this.deliveryPickUpWay=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
			//获取结算模式下拉框
			getDicts('settle_type').then(res=>{
				this.settlementMode=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
			
			//获取承运方下拉框
			getCarrierList({pageNum:1,pageSize:1000}).then(res => {
				//承运方下拉框
				this.carrierObjectId = res.rows.map(item => {
					return {
						value: item.carrierId,
						text: item.carrierName+' '+item.contactPerson+' '+item.phone
					}
				})
			})
			//获取车型下拉框
			getDicts('car_type').then(res=>{
				res.data.forEach(item=>{
					this.carType_[item.dictValue]=item.dictLabel
				})
				this.vehicle=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
			//获取车牌号下拉框
			getCarrierCarList({pageNum:1,pageSize:1000}).then(res=>{
				this.plateNumber=res.rows.map(item=>{
					return item.licensePlate
				})
			})
			//获取司机
			getDriverList({pageNum:1,pageSize:1000}).then(res => {
				//司机下拉框
				this.allDriverList = res.rows.map(item => {
					return {
						value: item.driverId,
						text: item.driverName,
						idCardNo:item.idCardNo,
						phoneNumber:item.phoneNumber,
						plateNumberName:item.plateNumber,
						driverJson:JSON.stringify(item)
					}
				})
				this.driverName=res.rows.map(item=>{
					return item.driverName
				})
				this.driverCardId=res.rows.map(item=>{
					return item.idCardNo
				})
				this.driverCardTel=res.rows.map(item=>{
					return item.phoneNumber
				})
			})
			//加载车次调度状态
			getDicts('flow_status').then(res=>{
				res.data.forEach(item=>{
					this.scheduleStatus[item.dictValue]=item.dictLabel
				})
			})
		},
		watch: {
			'formData.totalMileageFee': {
				handler(newVal, oldVal) {
					let val=Number(newVal)-Number(oldVal);
					this.formData.totalCarriageFee=Number(this.formData.totalCarriageFee||0)+val;
				},
			}
		},
		computed: {
			totalPrice() {
				let totalCarriageFee=Number(this.formData.totalCarriageFee||0)  //总运费
				let totalPackingFee=Number(this.formData.totalPackingFee||0)    //总包装费
				let shipPickUpFee=Number(this.formData.shipPickUpFee||0)        //提货费
				let deliveryPickUpFee=Number(this.formData.deliveryPickUpFee||0) //送货费
				let parcelInsuranceFee=Number(this.formData.waybillValueAdd.parcelInsuranceFee||0) //保价费
				let receiptFee=Number(this.formData.waybillValueAdd.receiptFee||0) //回单费
				let warehouseFee=Number(this.formData.waybillValueAdd.warehouseFee||0)  //仓储费
				let loadingFee=Number(this.formData.waybillValueAdd.loadingFee||0)   //装货费
				let unloadFee=Number(this.formData.waybillValueAdd.unloadFee||0)   //卸货费
				let drayage=Number(this.formData.waybillValueAdd.drayage||0)      //短驳费
				//let carryFee=Number(this.formData.waybillValueAdd.carryFee||0)	//搬运费
				let otherFee=Number(this.formData.waybillValueAdd.otherFee||0)	//其他费用
				let totalMoney=totalCarriageFee+totalPackingFee+shipPickUpFee+deliveryPickUpFee+parcelInsuranceFee+receiptFee+warehouseFee+loadingFee+unloadFee+drayage+otherFee;
				return totalMoney.toFixed(2);
			}
		},
		//退出页面自动保存
		destroyed() {
			console.log(this.formData)
			// this.formData.waybillFee=this.waybillFee
			// uni.setStorageSync('waybillDraft',this.formData)
			
			
			// this.formData.waybillFee=this.waybillFee
			// this.autoConfirm()   //保存运单
		},
		methods: {
			clickMoreSetting(falg){
				this.moreSetting=falg;
				if(!falg)  //点击更多设置
				{
					//承运商单选框选中状态
					this.carrierObjectFlag=false;
					this.formData.waybillCarrier={
						carrierObjectId:'',
						driverName:'',
						driverCardId:'',
						driverCardTel:'',
						vehicle:'',
						driverCarId:'',
						driverTrailerId:'',
						agent:'',
						tel:''
					}
					this.carInfo=[]
					this.formData.remark=''
				}
			},
			//选择司机
			inpuTdriverName(e){
				if(e)
				{
					let index=this.driverName.indexOf(e)
					let diver=this.allDriverList[index]
					this.driverJson=JSON.parse(diver.driverJson);
					this.formData.waybillCarrier.driverCardId=diver.idCardNo;
					this.formData.waybillCarrier.driverCardTel=diver.phoneNumber;
					this.formData.waybillCarrier.driverCarId=diver.plateNumberName;//车牌号
					this.inputPlateNumber(diver.plateNumberName)
				}
			},
			//选择司机身份证号
			inpuIdriverCardId(e){
				if(e)
				{
					let index=this.driverCardId.indexOf(e)
					let diver=this.allDriverList[index]
					this.driverJson=JSON.parse(diver.driverJson);
					this.formData.waybillCarrier.driverName=diver.text;
					this.formData.waybillCarrier.driverCardTel=diver.phoneNumber;
					this.formData.waybillCarrier.driverCarId=diver.plateNumberName;//车牌号
					this.inputPlateNumber(diver.plateNumberName)
				}
			},
			//选择司机电话
			inpuTdriverCardTel(e){
				if(e)
				{
					let index=this.driverCardTel.indexOf(e)
					let diver=this.allDriverList[index]
					this.driverJson=JSON.parse(diver.driverJson);
					this.formData.waybillCarrier.driverName=diver.text;
					this.formData.waybillCarrier.driverCardId=diver.idCardNo;
					this.formData.waybillCarrier.driverCarId=diver.plateNumberName;//车牌号
					this.inputPlateNumber(diver.plateNumberName)
				}
			},
			//车牌号
			inputPlateNumber(e){
				if(e)
				{
					//节流函数
					let that=this
					if(!that.statu)
					{
						return
					}
					that.statu=false
					setTimeout(()=>{
						getCarrierCarDetails(e).then(res=>{
							if(res.data)
							{
								that.carInfo=res.data
								that.formData.waybillCarrier.vehicle=res.data.carType
								if(JSON.stringify(this.driverJson) != "{}")
								{
									getScheduleListByDriverId({driverId:this.driverJson.driverId,carId:that.carInfo.carId}).then(res=>{
										that.scheduleList=res
									})
								}
							}
							else
							{
								that.carInfo=[]
							}
							
						})
						that.statu=true;
					},1000)
				}
				else
				{
					this.carInfo=[]
					this.scheduleList=[]
				}
			},
			//选择调度车次加入
			openSelectScheduleList(){
				this.$refs.alertDialog_scheduleList.open()
			},
			//选择车次
			radioChange_scheduleList(e) {
				//设置为车次
				this.schedule=JSON.parse(e.detail.value);
			},
			//确认设置调度车次
			dialogConfirm_scheduleList() {
				this.scheduleVo=this.schedule
			},
			//计算总运费、总包装费
			calculate(){
				let goodSourceList=JSON.parse(JSON.stringify(this.formData.goodSourceList))
				let goodSourceList_packingFee=goodSourceList.map(item=>item.packingFee)
				let goodSourceList_totalCarriageFee=goodSourceList.map(item=>item.carriageFee)
				
				//总包装费
				this.formData.totalPackingFee=goodSourceList_packingFee.reduce((a,b)=>{
					return Number(a||0)+Number(b||0);
				},0)
				//总运费
				this.formData.totalCarriageFee=goodSourceList_totalCarriageFee.reduce((a,b)=>{
					return Number(a||0)+Number(b||0);
				},0)
			},
			//接受保存增值服务后的数据
			otherFun_waybillValueAdd(bookList) {
				if(bookList){
					this.formData.waybillValueAdd=bookList
				}else{
					return
				}
			},
			//接受保存物品后的数据
			otherFun(bookList,index) {
				if(bookList){
					if(index)//编辑
					{
						this.formData.goodSourceList.splice(index,1,bookList)
					}
					else   //新增
					{
						this.formData.goodSourceList.push(bookList)
					}
					
					this.calculate()  //计算总运费、总包装费
					
				}else{
					return
				}
			},
			//选择原运单号,回填数据
			selectOutCode(e){
				this.oldOutCodeList.forEach(item=>{
					if(item.value===e)
					{
						this.formData=JSON.parse(item.waybillDetails)
						
						this.waybillFee=this.formData.waybillFee
						this.oldOutCode=this.formData.outCode
						
						//作退货单处理
						this.formData.waybillId='';
						this.formData.oldOutCode=this.formData.outCode
						this.formData.outCode=''
					}
				})
			},
			//收货方
			selectShipId(e){
				this.shipId.forEach(item=>{
					if(item.value===e)
					{
						this.formData.shipName=item.text
					}
				})
			},
			//发货方
			selectDeliveryId(e){
				this.deliveryId.forEach(item=>{
					if(item.value===e)
					{
						this.formData.deliveryName=item.text
					}
				})
			},
			//打开发货方地址簿
			open_shipAddress(){
				//获取地址簿
				this.shipId.forEach(item=>{
					if(item.value===this.formData.shipId)
					{
						this.addressList_ship=JSON.parse(item.customer).bookList
					}
				})
				
				this.$refs.alertDialog_address_ship.open()
			},
			//打开收货方地址簿
			open_deliveryAddress(){
				//获取地址簿
				this.deliveryId.forEach(item=>{
					if(item.value===this.formData.deliveryId)
					{
						this.addressList_delivery=JSON.parse(item.customer).bookList
					}
				})
				this.$refs.alertDialog_address_delivery.open()
			},
			//选择地址->发货方
			radioChange_ship(e) {
				//设置为地址
				this.address_ship=JSON.parse(e.detail.value);
			},
			//选择地址->收货方
			radioChange_delivery(e) {
				//设置为地址
				this.address_delivery=JSON.parse(e.detail.value);
			},
			//确认设置地址->发货方
			dialogConfirm_address_ship() {
				this.formData.shipContacts=this.address_ship.contactName 		//发货方联系人
				this.formData.shipContactTel=this.address_ship.phone 			//发货方联系电话
				this.formData.shipDistrictId=this.address_ship.bookDistrict		//发货方省市区、县ID
				this.formData.shipDistrictName=this.address_ship.bookDistrictName//发货方省市区名称
				this.formData.shipAddress=this.address_ship.bookAddress  		//发货方详细地址
			},
			//确认设置地址->收货方
			dialogConfirm_address_delivery() {
				this.formData.deliveryContacts=this.address_delivery.contactName	//收货方联系人
				this.formData.deliveryContactTel=this.address_delivery.phone 		//收货方联系电话
				this.formData.deliveryDistrictId=this.address_delivery.bookDistrict	//收货方省市区、县ID
				this.formData.deliveryDistrictName=this.address_delivery.bookDistrictName		//收货方省市区名称
				this.formData.deliveryAddress=this.address_delivery.bookAddress  		//收货方详细地址
				
				//查询价格方案
				getPlanPriceList({
					desDist:this.formData.deliveryDistrictId.slice(0,4)+'00',
					deptId:uni.getStorageSync('storage_data').vuex_userInfo.deptId
				})
				.then(res=>{
					console.log('价格方案')
					console.log(res)
				})
			},
			//展开&收缩物品信息
			spreadAndShrink(){
				this.spread=!this.spread
			},
			//新增物品
			addGoods(){
				uni.navigateTo({
					url:'/pages-operation/operation/addWaybill/addGoods'
				})
			},
			//编辑物品
			editGoodsList(index){
				uni.navigateTo({
					url:'/pages-operation/operation/addWaybill/addGoods?goodsDetails='+JSON.stringify(this.formData.goodSourceList[index])+'&index='+index
				})
			},
			//删除物品
			deleteGoodsList(index){
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定删除此物品？',
					success: function (res) {
						if (res.confirm) {
							that.formData.goodSourceList.splice(index,1)
							
							this.calculate()  //计算总运费、总包装费
							
						} else if (res.cancel) {
							
						}
					}
				});
			},
			//控货
			checkboxChange(e){
				if(e.detail.value.length!==0)
				{
					this.formData.cargoControl='1';  //控货
				}
				else
				{
					this.formData.cargoControl='0';  //非控货
				}
			},
			//增值服务弹出
			bindPickerChangeIncrementService(){
				uni.navigateTo({
					url:'/pages-operation/operation/addWaybill/waybillValueAdd?waybillValueAdd='+JSON.stringify(this.formData.waybillValueAdd)
				})
			},
			//消费抵扣弹出
			// bindPickerChangeConsumeDeduction(e){
			// 	this.index_consumeDeduction = e.detail.value
			// 	this.formData.consumeDeduction=this.array_consumeDeduction[this.index_consumeDeduction]
			// },
			//结算方式弹出
			// bindPickerChangeConsumeDeduction(e){
			// 	this.index_settlement = e.detail.value
			// 	this.formData.settlement=this.array_settlement[this.index_settlement]
			// },
			//运价说明
			tips(){
				this.$refs.popup.open()
			},
			//下单弹窗
			dialogToggle() {
				this.$refs.alertDialog.open()
			},
			//修改运单
			updateWayBillProfile(){
				this.$refs.form.validate().then(res => {
					if(!this.formData.waybillType)
					{
						uni.showToast({
							title: '运单类型不能为空',
							icon:'none'
						})
						return
					}
					if(this.formData.goodSourceList.length===0)
					{
						uni.showToast({
							title: '请至少添加1个物品',
							icon:'none'
						})
						return
					}
					if(!this.waybillFee.settlementMode)
					{
						uni.showToast({
							title: '结算方式不能为空',
							icon:'none'
						})
						return
					}
				
					uni.showLoading({
						title: '正在保存...',
					})
					updateWayBillProfile(this.formData).then(res => {
						uni.hideLoading()
						if (res.code == '200') {
							//新增成功后，删除本地草稿数据
							//uni.removeStorageSync('waybillDraft');
							uni.showToast({
								title: '保存成功',
								icon: 'none'
							})
							let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
							let nowPage = pages[pages.length - 1]; //当前页页面实例
							let prevPage = pages[pages.length - 2]; //上一页页面实例
							prevPage.$vm.otherFun('0') // 給上一頁綁定方法otherFun,傳參0（tabIndex：0）
							uni.navigateBack({
								delta: 1 // 可以不傳delta值，默認為1
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}		
					})	
				}).catch(err => {
					uni.showToast({
						title: err[0].errorMessage,
						icon: 'none'
					})
				})
			},
			//点击保存自动提交为'待提交'状态
			autoConfirm() {
				this.$refs.form.validate().then(res => {
					// if(!isSupervisor)
					// {
					// 	uni.showToast({
					// 		title: '请在【服务人员】中设置一名主管',
					// 		icon:'none'
					// 	})
					// 	return
					// }
				
					uni.showLoading({
						title: '正在保存...',
					})
					this.formData.submitted='0'  //保存
					this.formData.refund='1'  //退货单
					addWayBill(this.formData).then(res => {
						uni.hideLoading()
						if (res.code == '200') {
							//新增成功后，删除本地草稿数据
							//uni.removeStorageSync('waybillDraft');
							uni.showToast({
								title: '保存成功',
								icon: 'none'
							})
							let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
							let nowPage = pages[pages.length - 1]; //当前页页面实例
							let prevPage = pages[pages.length - 2]; //上一页页面实例
							prevPage.$vm.otherFun('0') // 給上一頁綁定方法otherFun,傳參0（tabIndex：0）
							uni.navigateBack({
								delta: 1 // 可以不傳delta值，默認為1
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}		
					})
				}).catch(err => {
					uni.showToast({
						title: err[0].errorMessage,
						icon: 'none'
					})
				})
			},
			//确认下单
			async dialogConfirm() {
				if(!this.formData.waybillType)
				{
					uni.showToast({
						title: '运单类型不能为空',
						icon:'none'
					})
					return
				}
				if(this.formData.goodSourceList.length===0)
				{
					uni.showToast({
						title: '请至少添加1个物品',
						icon:'none'
					})
					return
				}
				if(!this.waybillFee.settlementMode)
				{
					uni.showToast({
						title: '结算方式不能为空',
						icon:'none'
					})
					return
				}
				
				uni.showLoading({
					title: '正在提交...',
				})
				
				if(this.oldOutCode=='')  //第一次下单
				{
					this.formData.submitted='1'  //提交
					this.formData.refund='1'  //退货单
					//加入调度单
					if(this.scheduleList.length!=0&&this.scheduleVo.scheduleNo) //如果当前已经选择调度车次信息
					{
						this.formData.scheduleNo=this.scheduleVo.scheduleNo
						this.formData.scheduleStatus='400'
						this.formData.scheduleVo=this.scheduleVo
					}
					await addWayBill(this.formData).then(res => {
						uni.hideLoading()
						if (res.code == '200') {
							//新增成功后，删除本地草稿数据
							//uni.removeStorageSync('waybillDraft');
							
							//加入调度单
							if(this.scheduleList.length!=0&&this.scheduleVo.scheduleNo) //如果当前已经选择调度车次信息
							{
								let form=JSON.parse(JSON.stringify(this.scheduleVo))
								form.carJson=form.carVo
								form.driverJson=form.driverVo
								let waybillIds=form.waybillList.map(item=>item.waybillId)
								waybillIds.push(res.data.waybillId)
								updateSchedule({waybillIds:waybillIds,...form}).then(res2=>{
									if(res2.code == '200')
									{
										uni.showToast({
											title: '加入调度车次成功',
											icon: 'none'
										})
									}
									else
									{
										uni.showToast({
											title: '加入调度车次失败',
											icon: 'none'
										})
									}
								})
							}
							uni.showToast({
								title: '提交成功',
								icon: 'none'
							})
							let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
							let nowPage = pages[pages.length - 1]; //当前页页面实例
							let prevPage = pages[pages.length - 2]; //上一页页面实例
							prevPage.$vm.otherFun('0') // 給上一頁綁定方法otherFun,傳參0（tabIndex：0）
							uni.navigateBack({
								delta: 1 // 可以不傳delta值，默認為1
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}	
					})
				}
				else  //第二次下单,先保存，后提交
				{
					//修改保存
					
					//加入调度单
					if(this.scheduleList.length!=0&&this.scheduleVo.scheduleNo) //如果当前已经选择调度车次信息
					{
						this.formData.scheduleNo=this.scheduleVo.scheduleNo
						this.formData.scheduleStatus='400'
						this.formData.scheduleVo=this.scheduleVo
					}
					await updateWayBillProfile(this.formData).then(res => {
						uni.hideLoading()
						if (res.code == '200') {
							//提交
							updateWayBillStatus(110,this.waybillId).then(res => {
								uni.hideLoading()
								if (res.code == '200') {
									//新增成功后，删除本地草稿数据
									//uni.removeStorageSync('waybillDraft');
									
									//加入调度单
									if(this.scheduleList.length!=0&&this.scheduleVo.scheduleNo) //如果当前已经选择调度车次信息
									{
										let form=JSON.parse(JSON.stringify(this.scheduleVo))
										form.carJson=form.carVo
										form.driverJson=form.driverVo
										let waybillIds=form.waybillList.map(item=>item.waybillId)
										waybillIds.push(this.waybillId)
										updateSchedule({waybillIds:waybillIds,...form}).then(res2=>{
											if(res2.code == '200')
											{
												uni.showToast({
													title: '加入调度车次成功',
													icon: 'none'
												})
											}
											else
											{
												uni.showToast({
													title: '加入调度车次失败',
													icon: 'none'
												})
											}
										})
									}
									uni.showToast({
										title: '提交成功',
										icon: 'none'
									})
									let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
									let nowPage = pages[pages.length - 1]; //当前页页面实例
									let prevPage = pages[pages.length - 2]; //上一页页面实例
									prevPage.$vm.otherFun('0') // 給上一頁綁定方法otherFun,傳參0（tabIndex：0）
									uni.navigateBack({
										delta: 1 // 可以不傳delta值，默認為1
									})
								} else {
									uni.showToast({
										icon: 'none',
										title: res.msg
									})
								}	
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}		
					})
				}
			},
			
		},
	}
</script>

<style scoped>
.buttonHover {
		opacity: 0.6;
	}
	::v-deep .uni-border-left{
	    border-left-color: #f0f0f0;
	    border-left-style: solid;
	    border-left-width: 1px;
	    background-color: rgb(157,81,38);
	    border-radius: 0 0 11px 0;
	    /* color: white; */
	}
	
	::v-deep .uni-button-color{
	    color: #ffffff;
	}
	
	::v-deep .uni-select__input-box{
		width: 0vw;
	}
	
</style>